import type { RequestOption } from "../../index.js";
import { fields, Operation } from "./util.js";

export const elementEvent: RequestOption = {
    name: "0x04 执行动作",
    description: "执行动作",
    fields: [
        fields.op(Operation.ElementEvent),
        fields.crc,
        {
            name: "length",
            kind: "custom",
            cb(ctx) {
                let len = 0;
                for (const key in ctx.lengths) {
                    len += ctx.lengths[key]!;
                }
                return [len - 3];
            },
        },
        {
            name: "画面号",
            kind: "u16",
            value: 1,
        },
        {
            name: "图元 ID",
            kind: "u16",
            value: 1,
        },
        {
            name: "事件类型",
            kind: "enum",
            enums: {
                未指定: 0,
                按下: 1,
                抬起: 2,
                点击: 3,
                输入: 4,
                页面打开: 5,
                页面关闭: 6,
            },
            value: 1,
            size: 1,
        },
    ],
};
